/*
ts类型:String , number , boolean , null , undefined
联合类型: type myType = string | number
交叉类型: type myType = { name: string } & { age: number }
类型别名与接口: interface Person { name: string; age: number; }
泛型: function identity<T>(arg: T):T { return arg;}
条件类型: type IsString<T> = T extends string  ? 'Yes' : 'No';

js类型:String , number , boolean , null , undefined , symbol , bigint
js引用类型：Object、Array、Function、Date

*/

/*
let a = 1;
let b = {};
let i = [1,2,3];
console.log(a);
console.log(b);
for (let iKey in i) {
    console.log(iKey);
}

type Person<T> = {
    name: string;
    age: number;
    info: T
}
const person1:Person<{hobby:String[]}> = {
    name: "1",
    age: 18,
    info: {
        hobby:["eat","sleep"]
    }
}
console.log(person1);*/


/*
class Person {}

//泛型的约束
class Student extends Person {}

//2.约束泛型
function say<T extends {id: string}>(a: T):T{
    return a;
}
say({id:"1"});


//3.条件类型
type IsString<T> = T extends string ? true : false;
const isString1: IsString<"hello"> = true;
const isString2: IsString<number> = false;
console.log(isString1);
console.log(isString2);
*/

//工具类型
// type Person = {name: string, age: number};
//用已有类型来派生新的类型
//要什么 就Pick什么(取) 不要什么就Omit什么(丢)
// type NamedPerson = Pick<Person, "name">;
// type AgedPerson = Omit<Person, "age">;

// 类型保护，通过判断类型来推导类型
/*
type Value =string | number;
const value:Value = 'string';

value.toFixed();//会报错 因为value可能是string类型*/

//在使用之前就知道的类型，可以使用类型保护
type Value =string | number;
let value:Value = "123";
function isString(value: Value):value is string {//当value的值满足条件的时候
    return typeof value === 'string';
}

console.log(isString(value));